<?php

use yii\db\Migration;

class m180418_073534_create_msg_log extends Migration
{
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
        }
        $this->createTable('{{%msg_log}}', [
            'id' => $this->primaryKey(),
            'site_id' => $this->integer()->defaultValue(0)->notNull()->comment('分店编号'),
            'admin_id' => $this->integer()->defaultValue(0)->comment('操作管理员id'),
            'message_type_id' => $this->integer()->defaultValue(0)->notNull()->comment('对应的类型id'),
            'send_way' => $this->string(100)->notNull()->comment('发送方式（sms/email/sys/wechat）'),
            'send_group' => $this->string(100)->defaultValue(null)->comment('接收组类型'),
            'receiver_info' => $this->string(255)->notNull()->comment('接收者信息（手机号、邮箱、微信openid，系统消息则是用户id）'),
            'message_name' => $this->string(255)->defaultValue(null)->comment('消息名称（邮件标题、微信消息标题）'),
            'message_text' => $this->text()->defaultValue(null)->comment('消息内容'),
            'send_time' => $this->integer(11)->defaultValue(0)->comment('消息发送时间'),
            'state' => $this->smallInteger(1)->defaultValue(0)->notNull()->comment('0未发送、1已发送、2发送失败'),
            'error_info' => $this->text()->defaultValue(null)->comment('错误信息'),
            'created_at' => $this->integer(11)->defaultValue(0)->notNull()->comment('创建时间'),
        ],$tableOptions);
    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {
        $this->dropTable('{{%msg_log}}');
    }
}
